home *** CD-ROM | disk | FTP | other *** search
- /*
- $Id: GETCH.C,v 1.2 1994/02/05 18:46:56 gbj Exp user $
- */
-
- /*
- $Log: GETCH.C,v $
- // Revision 1.2 1994/02/05 18:46:56 gbj
- // Beta release
- //
- // Revision 1.1 1994/01/30 17:23:24 gbj
- // Initial revision
- //
- */
-
- //#define TEST
-
- //================================================================
- //
- // Replace standard getch() so that the nasty PC keys can be
- // simulated.
- //
- // Does not deal with every possible scan code.
- //
- // PC Translations:
- //
- // PC Value ATARI VALUE ==>
- //
- // PGUP 0x49 sUP 0x4838 0x4900
- // PGDN 0x51 sDN 0x5032 0x5100
- // END 0x4f sHOME 0x4737 0x4f00
- // F1 (help) 0x3b HELP 0x6200 0x3b00
- //
- //================================================================
-
- #include <osbind.h>
-
- static int next_char=0;
-
- int getch(void)
- {
- long x;
- int scan_code, ascii_code;
- int debug_next_char;
-
- // If a pending character, return it
- if (next_char)
- {
- ascii_code=next_char;
- next_char=0;
- debug_next_char=next_char;
- return ascii_code;
- }
-
- // Get the next kepress and set up ascii_code and scan_code
- x=Cnecin();
- ascii_code=x&0x000000ff;
- scan_code=(x&0x00ff0000)>>16;
-
- // Now, if ascii_code is 0, we already have one of the standard
- // extended characters, so set next_char from scan_code, return 0.
- // But, check for HELP key and translate to F1
-
- if (!ascii_code)
- {
- next_char=scan_code&0xff;
- debug_next_char=next_char;
- if (scan_code == 0x62) // HELP
- {
- next_char=0x3b; // to F1
- debug_next_char=next_char;
- }
- return ascii_code;
- }
-
- // Right, we have a possible funny character
- // If it is a normal char, set next_char to NULL and return ascii_code.
- // Otherwise, if it is one we are interested in, return NULL and
- // set next_char as necessary.
-
- if (scan_code == 0x48) // sUP to PGUP
- {
- ascii_code=0;
- next_char=0x49;
- debug_next_char=next_char;
- }
- else if (scan_code == 0x50) // sDN to PGDN
- {
- ascii_code=0;
- next_char=0x51;
- debug_next_char=next_char;
- }
- else if (scan_code == 0x47) // sHOME to END
- {
- ascii_code=0;
- next_char=0x4f;
- debug_next_char=next_char;
- }
- else // Not interested in it
- {
- next_char=0;
- debug_next_char=next_char;
- }
- return ascii_code;
- }
-
- #ifdef TEST
- void main(void)
- {
- int c;
-
- while ((c=getch()) != '*')
- printf("%2x ", c);
- exit(0);
- }
- #endif